import api from "../../../common/api";
import {setData} from "../../../models/transferData";
import constant from '../../../common/constant';
const app = getApp();

Page({
  /**
   * 页面的初始数据
   */
  data: {
    pageUrl: "/pages/cooperation/houseEdit/houseEdit",
    rentCount: 0,
    salesCount: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    getApp().globalData.loginPromise.then(() => {
      if(options.aid){
        wx.gio('track', constant.RELEASE_FROM, {
          [constant.RELEASE_HOUSE_INFO]: '认证短信',
        })
      }
    });
  },

  handleMyErshou() {
    wx.navigateTo({
      url: `/pages/cooperation/selectHouseTeamwork/selectHouseTeamwork?houseType=SALES`
    });
  },
  handleMyChuzu() {
    wx.navigateTo({
      url: `/pages/cooperation/selectHouseTeamwork/selectHouseTeamwork?houseType=RENT`
    });
  },

  handleErshou() {
    wx.setStorageSync("currentStatus", 1);
    setData('selectHouseAreaEnterNextPage', this.data.pageUrl)

    wx.navigateTo({
      url: `/pages/cooperation/choose/choose`
      // url: `/pages/addHouse/chooseHouse/chooseHouse`
    });
  },

  handleChuzu() {
    wx.setStorageSync("currentStatus", 2);
    setData('selectHouseAreaEnterNextPage', this.data.pageUrl)
    wx.navigateTo({
      url: `/pages/cooperation/choose/choose`
      // url: `/pages/addHouse/chooseHouse/chooseHouse`
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    app.globalData.loginPromise.then(({
      sessionUser
    }) => {
      api.queryAvailablePublishHouseCount({
        userId: sessionUser.id,
        city: app.globalData._wx_city
      }, ({
        data
      }) => {
        let content = data.content;
        this.setData({
          rentCount: content.rentCount,
          salesCount: content.salesCount,
        });
      });
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

});